/**
 * @ClassName LC122
 * 买卖股票的最佳时期II
 * @Author ykx
 * @Date 2024/6/29 9:59
 * @Version 1.0
 */
public class LC122 {
    public static void main(String[] args) {
        LC122 lc122 = new LC122();
        System.out.println(lc122.maxProfit(new int[]{7, 6, 4, 3, 1}));
    }

    public int maxProfit(int[] prices) {
        int maxProfit = 0;
        for (int i = 1; i < prices.length; i++) {
            if (prices[i - 1] < prices[i]) {
                maxProfit += (prices[i] - prices[i - 1]);
            }
        }
        return maxProfit;
    }
}
